package com.lzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzy.entity.Class;
import com.lzy.entity.Result;
import com.lzy.mapper.ClassMapper;
import com.lzy.service.IClassService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-04-26
 */
@Service
public class ClassServiceImpl extends ServiceImpl<ClassMapper, Class> implements IClassService {

    @Autowired
    private ClassMapper classMapper;

    @Override
    public IPage getPage(Page<Class> page, HashMap param) {
        return baseMapper.getPage(page, param);
    }

    // 新增班级
    @Override
    public Result addClass(Class classInfo) {
        // 判断班级是否存在
        LambdaQueryWrapper<Class> eq = new LambdaQueryWrapper<Class>().eq(Class::getClassName, classInfo.getClassName());
        if (this.getOne(eq) != null) {
            return Result.fail("班级已存在");
        }
        return this.save(classInfo) ? Result.success() : Result.fail();
    }
}
